package com.bkhc.product.api;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.annotation.WebRestController;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.product.entity.Partner;
import com.bkhc.product.service.PartnerService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pcq
 * @date 2021/6/20 17:57
 */
@RestController
@Api("厂商管理服务")
@RequestMapping("/partner")
@ApiPackage(code="partner-api",name="厂商管理服务",description = "后台厂商管理服务操作接口")
public class PartnerController extends CommonController{
    private static final Logger logger = LoggerFactory.getLogger(PartnerController.class);
    @Autowired
    private PartnerService partnerSerivce;

    @ApiOperation(code="addPartner",name="添加厂商",description = "添加厂商")
    @AuditLog(object="partner",operation = "添加厂商",type = OperationEnum.query)
    @RequestMapping(path = "/addPartner",method = RequestMethod.POST)
    public ResultJson<?> addPartner(@RequestBody(required=true) Partner partner) {
        ResultJson<?> res = partnerSerivce.addPartner(partner);
        return res;
    }

    @ApiOperation(code="deletePartner",name="删除厂商",description = "删除厂商" ,type = "common")
    @AuditLog(object="deletePartner",operation = "删除厂商",type = OperationEnum.query)
    @RequestMapping(path = "/deletePartner/{partnerCode}",method = RequestMethod.POST)
    public ResultJson<?> deletePartner(@PathVariable(name = "partnerCode") String partnerCode) {
        ResultJson<?> res = partnerSerivce.deletePartner(partnerCode);
        return res;
    }

    @ApiOperation(code="updatePartner",name="修改厂商",description = "修改厂商")
    @AuditLog(object="partner",operation = "修改厂商",type = OperationEnum.update)
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    public ResultJson<?> updatePartner(@RequestBody(required=true) Partner partner) {
        ResultJson<?> res = partnerSerivce.updatePartner(partner);
        return res;
    }


    @ApiOperation(code="queryPartnerList",name="查询厂商",description = "查询厂商")
    @AuditLog(object="partner",operation = "查询厂商",type = OperationEnum.query)
    @RequestMapping(path = "/list/{pageNum}/{pageSize}",method = RequestMethod.GET)
    public ResultJson<?> queryPartnerList(@RequestParam(required=false,name="partnerName") String partnerName,
                                    @RequestParam(required=false,name="brandCode") String brandCode,
                                    @PathVariable(name="pageNum") int pageIndex,
                                    @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = partnerSerivce.queryPartnerList(partnerName,brandCode,pageIndex,pageSize);
        return res;
    }

    @ApiOperation(code="queryPartnerDetail",name="查询厂商详情",description = "查询厂商详情")
    @AuditLog(object="partner",operation = "查询厂商详情",type = OperationEnum.query)
    @RequestMapping(path = "/info",method = RequestMethod.POST)
    public ResultJson<?> queryPartnerDetail(@RequestParam(required=true,name="partnerCode") String partnerCode) {
        ResultJson<?> res = partnerSerivce.queryPartnerDetail(partnerCode);
        return res;
    }

    @ApiOperation(code="generatePartnerAcount",name="生成厂商账号",description = "生成厂商账号",type = "common")
    @AuditLog(object="partner",operation = "生成厂商账号",type = OperationEnum.query)
    @RequestMapping(path = "/generatePartnerAcount",method = RequestMethod.GET)
    public ResultJson<?> generatePartnerAcount() {
        ResultJson<?> res = partnerSerivce.generatePartnerAcount();
        return res;
    }




}
